/******************************************************************************
Copyright:
2009 Jens Collin (jens.collin@dinomin.com)

This file is part of Envox Decompiler.

Envox Decompiler is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Envox Decompiler is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with KitchenOS.  If not, see <http://www.gnu.org/licenses/>.

******************************************************************************/
using System;

namespace EnvoxDecompiler
{
	/// <summary>
	/// Summary description for Block_Delay.
	/// </summary>
	public class Block_XMLCreateDocument : Block
	{

		private string _docHandle;

		public override TYPE GetBlockType()
		{
			return TYPE.XMLCreateDocument;
		}

		public override string GetXML(int x, int y)
		{
			Trace.Debug("Block_XMLCreateDocument::GetXML Started.");	
			// <XMLCreateDocument name="NAME" rect="X 32 96 56"
			string xml = "\t\t\t<XMLCreateDocument name=\"" + Utils.XmlString(_name) + "\" rect=\"" + x + " " + y + " 96 56\"";
			//  ...description="DESC"...
			xml += GetDescriptionXML();
			//  ...clearDTMF="_clearDTMFBuffer"...
			xml += GetClearDTMFXML();
			// ...minUserLevel="_userLevel"
			xml += GetMinUserLevelXML();
			// ...cpMessage=""...
			xml += GetControlPanelMessageXML();
			// ...documentHandle="HANDLE" >
			xml += " documentHandle=\"" + Utils.XmlString(_docHandle) + "\">\r\n";

			// <Inputs>
			xml += GetInputsXML(_blockId);
		
			// <Outputs>
			xml += GetOutputsXML();

			// <Logs>
			xml += GetLogsXML();
			
			xml += GetHandledErrorsXML();

			// </XMLCreateDocument>
			xml +="\t\t\t</XMLCreateDocument>\r\n";
			return xml;
		}

		public Block_XMLCreateDocument(byte[] rawData) : base(rawData)
		{
			// base has moved _currentPos to our start position.

			outputErrorIds.Add(new BlockOutput(OUTPUT.Next, 0));
			outputErrorIds.Add(new BlockOutput(OUTPUT.Exist, 135));
			outputErrorIds.Add(new BlockOutput(OUTPUT.InvalidHandle, 162));
			outputErrorIds.Add(new BlockOutput(OUTPUT.Failed_2, 141));
			
			Trace.Debug("Block_XMLCreateDocument created.");

			_currentPos += 4;

			// Document handle
			_docHandle = Utils.DataToString(rawData, _currentPos);
			_currentPos = _currentPos + Utils.DataStringLength(rawData, _currentPos);

		
			Trace.Debug("Doc handle: " + _docHandle);
		}
	}
}
